package cn.edu.scau.cmi.huangjunxi.client;

import org.springframework.context.ApplicationContext;

import cn.edu.scau.cmi.huangjunxi.spring.domain.Student;
import cn.edu.scau.cmi.huangjunxi.spring.domain.Teacher;
import cn.edu.scau.cmi.huangjunxi.spring.util.ApplicationContextUtil;

public class SpringApplicationContextClient {
	
	private static Teacher teacher;
	private static Student student;


	public static void main(String[] args) {
		ApplicationContext ac = getApplicationContext();
		student=(Student) ac.getBean("wang");
		teacher=(Teacher) ac.getBean("liangzaoqing");
		//System.out.println(zhangsan.getName()+zhangsan.getTutor().getName());
		System.out.println("Student name: "+student.getName()+"\nid: "+student.getId()+"\ntutor: "+student.getTutor().getName());
		System.out.println("Teacher name: "+teacher.getName()+"\nid: "+teacher.getId());
	}
	
	private static ApplicationContext getApplicationContext() {
		ApplicationContext applicationcontext=ApplicationContextUtil.getApplicationContext();
		return applicationcontext;
	}
	
	static void outputContext()
	{
		ApplicationContext ac = getApplicationContext();
		student=(Student) ac.getBean("wang");
		teacher=(Teacher) ac.getBean("liangzaoqing");
		//System.out.println(zhangsan.getName()+zhangsan.getTutor().getName());
		System.out.println("Student name: "+student.getName()+"\nid: "+student.getId()+"\ntutor: "+student.getTutor().getName());
		System.out.println("Teacher name: "+teacher.getName()+"\nid: "+teacher.getId());
	}
}
